home *** CD-ROM | disk | FTP | other *** search
/ Quick PC 62 / Quick PC 62.iso / I386 / IIS5_01.CAB / IIS_iiaspstr.inc < prev    next >
Encoding:
Text File  |  1998-09-16  |  1.1 KB  |  40 lines

  1. <%
  2. ' iiaspstr.inc
  3.  
  4. ' Function:        sJSLiteral
  5. ' Arguments:    String s [in]
  6. ' Return:        String
  7. '
  8. ' Utility function to fix problems that can happen when using an ASP string
  9. ' variable as a JavaScript string literal. If the string variables may contain
  10. ' embeded single or double quotes (', ") or back slashes (\) then sJSLiteral
  11. ' should be used to escape these invalid characters
  12. '
  13.  
  14. Const iSingleQuote = 39
  15. Const iDoubleQuote = 34
  16. Const sBackSlash = "\"
  17.  
  18. Dim sLiterals
  19. sLiterals = Array( sBackSlash, "" & Chr(iSingleQuote), "" & Chr(iDoubleQuote) )
  20.  
  21. Function sJSLiteral( s )
  22.     Dim i, pos, length, sNew
  23.     
  24.     length = Len(s)
  25.     pos = 0
  26.     sNew = s
  27.     For i = LBound(sLiterals) To UBound(sLiterals)
  28.         Do
  29.             pos = InStr(pos + 1, sNew, CStr(sLiterals(i)), 0)
  30.             If pos > 0 Then
  31.                 sNew = Left(sNew, pos - 1) & sBackSlash & CStr(sLiterals(i)) & Right(sNew, length - pos)
  32.                 length = Len(sNew)
  33.                 pos = pos + 1
  34.             End If
  35.         Loop Until pos = 0
  36.     Next
  37.     
  38.     sJSLiteral = sNew
  39. End Function
  40. %>